<?php
/**
 * Created by PhpStorm.
 * desc:
 * User: wang.yizhe
 * Date: 2023/12/19
 * Time: 18:29
 */

namespace App\Http\Controllers\Manage;

use App\Http\Controllers\BaseController;
use App\Repositories\ReceiversRepository;
use App\Services\ActivityService;
use App\Services\Manage\CommonManageService;
use App\Services\Manage\ReceiverImportService;
use App\Services\ReceiverService;
use App\Services\VillageService;
use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class CommonController extends BaseController
{

    /**
     * 活动列表
     * @param  Request  $request
     * @return JsonResponse
     */
    public function activityList(Request $request)
    {
        $list = CommonManageService::activityList();

        return $this->success($list);
    }

    /**
     * 领券人导入文件转换，用于支持微信小程序政务识别插件的名单导入
     * @param  Request  $request
     * @return JsonResponse
     */
    public function receiverFileConvert(Request $request)
    {
        $file = $request->file('file');

        $res = CommonManageService::receiverFileConvert($file);

        return $this->success([]);
    }

    /**
     * 上传图片，公共
     * @param  Request  $request
     * @return JsonResponse
     */
    public function uploadPic(Request $request)
    {
        $file = $request->file('file');
        $type = $request->get('type'); //1.活动头图；2.券预览图

        $res = CommonManageService::uploadPic($type, $file);
        if ($res['errcode']) {
            return $this->error(401, $res['errmsg']);
        }

        return $this->success($res['data']);
    }

    /**
     * 协助者导入文件转换，用于支持微信小程序政务识别插件的名单导入
     * @param  Request  $request
     * @return JsonResponse
     */
    public function assistantFileConvert(Request $request)
    {
        $file = $request->file('file');

        $res = CommonManageService::assistantFileConvert($file);

        return $this->success([]);
    }


}
